/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Affichage;

import Metier.Dialogue;
import Metier.Lieu;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

/**
 *
 * @author Loick
 */
public class AjouterLieu extends JFrame {

    private javax.swing.JButton BTNAjouterLieu;
    private javax.swing.JButton BTNParcourirLieu;
    private javax.swing.JLabel LBLAjouterLieu;
    private javax.swing.JLabel LBLCheminImage;
    private javax.swing.JLabel LBLDescription;
    private javax.swing.JLabel LBLHyperlienLieu;
    private javax.swing.JLabel LBLNom;
    private javax.swing.JTextArea TXTADescriptionLieu;
    private javax.swing.JTextField TXTCheminLieu;
    private javax.swing.JTextField TXTNomLieu;
    private javax.swing.JTextField TXTUrlLieu;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;

    public AjouterLieu() {

        LBLAjouterLieu = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        LBLNom = new javax.swing.JLabel();
        LBLDescription = new javax.swing.JLabel();
        LBLHyperlienLieu = new javax.swing.JLabel();
        LBLCheminImage = new javax.swing.JLabel();
        TXTNomLieu = new javax.swing.JTextField();
        jSeparator3 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        TXTADescriptionLieu = new javax.swing.JTextArea();
        TXTUrlLieu = new javax.swing.JTextField();
        TXTCheminLieu = new javax.swing.JTextField();
        BTNAjouterLieu = new javax.swing.JButton();
        BTNParcourirLieu = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        LBLAjouterLieu.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        LBLAjouterLieu.setText("Ajouter un lieu");

        LBLNom.setText("Nom du lieu");

        LBLDescription.setText("Description du lieu");

        LBLHyperlienLieu.setText("Lien vers la page du lieu");

        LBLCheminImage.setText("Chemin de l'image");

        jSeparator3.setOrientation(javax.swing.SwingConstants.VERTICAL);

        TXTADescriptionLieu.setColumns(20);
        TXTADescriptionLieu.setRows(5);
        jScrollPane1.setViewportView(TXTADescriptionLieu);

        BTNAjouterLieu.setText("Ajouter");

        BTNAjouterLieu.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Dialogue passerlieu = new Dialogue();
                Lieu DefLieu = new Lieu();
                DefLieu.setLibelle(TXTNomLieu.getText());
                DefLieu.setCarte(TXTCheminLieu.getText());
                DefLieu.setUrl(TXTUrlLieu.getText());
                DefLieu.setTexte(TXTADescriptionLieu.getText());
                
                passerlieu.insertLieu(DefLieu);
            }
        });

        BTNParcourirLieu.setText("Parcourir");

        BTNParcourirLieu.addActionListener(new java.awt.event.ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    JFileChooser Parcourir = new JFileChooser();
                    Parcourir.setFileSelectionMode(JFileChooser.FILES_ONLY);

                    Parcourir.setAcceptAllFileFilterUsed(true);

                    int Valretour = Parcourir.showOpenDialog(null);
                    if (Valretour == JFileChooser.APPROVE_OPTION) {
                        TXTCheminLieu.setText(Parcourir.getSelectedFile().getName());
                    }
                    FileInputStream sourceFile = null;
                    FileOutputStream destiFile = null;
                    sourceFile = new FileInputStream(Parcourir.getSelectedFile().getAbsolutePath());
                    destiFile = new FileOutputStream("F:\\A2ProjetJava\\ProjetJava2\\mini-sig-java\\MiniSig\\" + Parcourir.getSelectedFile().getName());
                    byte buffer[] = new byte[512 * 1024];
                    int nbLecture;
                    try {
                        while ((nbLecture = sourceFile.read(buffer)) != -1) {
                            destiFile.write(buffer, 0, nbLecture);
                        }
                    } catch (IOException ex) {
                        Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                    } finally {
                        try {
                            sourceFile.close();
                            destiFile.close();
                        } catch (IOException ex) {
                            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
                }

//                JFileChooser Parcourir = new JFileChooser();
//                Parcourir.setFileSelectionMode(JFileChooser.FILES_ONLY);
//
//                Parcourir.setAcceptAllFileFilterUsed(true);
//
//                int Valretour = Parcourir.showOpenDialog(null);
//                if (Valretour == JFileChooser.APPROVE_OPTION) {
//                    TXTCheminLieu.setText(Parcourir.getSelectedFile().getName());
//                }

            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(LBLAjouterLieu)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1))
                .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(LBLNom)
                .addComponent(LBLHyperlienLieu)
                .addComponent(LBLCheminImage)
                .addComponent(LBLDescription))
                .addGap(0, 0, Short.MAX_VALUE))
                .addComponent(BTNAjouterLieu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(TXTUrlLieu, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createSequentialGroup()
                .addComponent(TXTCheminLieu, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(BTNParcourirLieu)))
                .addComponent(TXTNomLieu, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap()));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(LBLAjouterLieu))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addGroup(layout.createSequentialGroup()
                .addComponent(LBLNom)
                .addGap(18, 18, 18)
                .addComponent(LBLHyperlienLieu)
                .addGap(18, 18, 18)
                .addComponent(LBLCheminImage)
                .addGap(18, 18, 18)
                .addComponent(LBLDescription)
                .addGap(18, 18, 18)
                .addComponent(BTNAjouterLieu, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(layout.createSequentialGroup()
                .addComponent(TXTNomLieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(TXTUrlLieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(TXTCheminLieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(BTNParcourirLieu, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGroup(layout.createSequentialGroup()
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator3)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>
}